package Method;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        //join:线程的插队，让插队线程执行玩全部的任务，再接着执行之前的任务
        T2 t2 = new T2();
        t2.start();

        for (int i = 1;i<=20;i++){

            System.out.println("hi" + i);
            if(i == 5){
                t2.join();//t2线程插队，限制性完t2线程的任务，再接着执行main线程的任务
            }
            Thread.sleep(1000);
        }
    }
}

class T2 extends Thread{
    private int count = 0;
    @Override
    public void run() {
        while (count < 20){
            System.out.println("hello" + (++count));

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
